import sys
import matplotlib
from PyQt5 import QtQml
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQml import QQmlApplicationEngine, qmlRegisterType
from PyQt5 import QtQml
from PyQt5.QtQml import QQmlApplicationEngine
import PyQt5

def main():
    app = QGuiApplication(sys.argv)

    # qmlRegisterType(FigureCanvasQTAggToolbar, "Backend", 1, 0, "FigureToolbar")

    imgProvider = MatplotlibIconProvider()

    engine = QQmlApplicationEngine(parent=app)
    engine.addImageProvider("mplIcons", imgProvider)

    context = engine.rootContext()
    data_model = DataSeriesModel()
    context.setContextProperty("dataModel", data_model)
    mainApp = Form(data=data_model)
    context.setContextProperty("draw_mpl", mainApp)

    engine.load(
        QUrl('main.qml'))

    win = engine.rootObjects()[0]
    mainApp.figure = win.findChild(QObject, "figure").getFigure()

    rc = app.exec_()
    sys.exit(rc)